package com.kehao.leetcode.jzoffer;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/23 14:38
 */
public class JZSolution024 {
    private static class ListNode {
        int val;
        ListNode next;
        ListNode() {
        }
        ListNode(int val) {
            this.val = val;
        }
        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
    public ListNode reverseList(ListNode head) {
        if(head==null) return null;
        ListNode h = new ListNode();
        ListNode p = head;
        ListNode p1 = p.next;
        while (p!=null){
            p.next = h.next;
            h.next = p;
            p = p1;
            p1 = p1==null?p1:p1.next;
        }
        return h.next;
    }
}
